<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>系统日志列表 Sys Log</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/statics/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/statics/style/admin.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">按月份搜索</label>
              <div class="layui-input-block">
                <select name="month" lay-verify="" id="layui-form-month">
                  <option  th:each="m:${months}" th:value="${m}" th:text="${m}" th:selected="${m == month}"></option>
                </select>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-block">
                <input class="layui-input" name="user-name" id="layui-form-user-name" autocomplete="off" th:value="${userName}">
              </div>
            </div>
            <button class="layui-btn" data-type="search">搜索</button>
          </div>
        </div>
        <div class="layui-card-body">

          <table class="layui-hide" id="sys-log-table" lay-filter="sys-log-filter"></table>

          <script type="text/html" id="sys-log-table-toolbar">
            <div class="layui-btn-container">
            </div>
          </script>

        </div>
      </div>
    </div>
  </div>
</div>


<script th:src="@{/statics/layui/layui.js}"></script>
<script th:inline="none">
  layui.config({
    base: '/statics/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var admin = layui.admin
    ,table = layui.table;

      var tableIns = table.render({
        elem: '#sys-log-table'
        ,url: '/api/log/page'
        ,id:'id'
        ,toolbar: '#sys-log-table-toolbar'

        ,cols: [[
          {field:'id',width:60, title: 'ID'}
          ,{field:'userName', width:100, title: '用户名', sort: true}
          ,{field:'ipAddress', width:150, title: 'IP地址'}
          ,{field:'url', width:300, title: '地址'}
          ,{field:'params', width:200, title: '参数'}
          ,{field:'method', width:80, title: '方法', sort: true}
          ,{field:'createTime', width:200, title: '时间', sort: true}
        ]]
        ,page: true
        ,request: {
            pageName:'pageNum'
            ,limitName: 'pageSize'
        }
    });

      //头工具栏事件
      table.on('toolbar(sys-log-filter)', function(obj){
          var checkStatus = table.checkStatus('id');
          switch(obj.event){
              case 'clear':
                  //var data = checkStatus.data;
                  //layer.msg('选中了：'+ data.length + ' 个');
                  $.ajax({
                      url: '/api/log/clear',
                      method: 'DELETE',
                      dataType: 'JSON',
                      success: function (res) {
                          if (res.code == '0') {
                              tableIns.reload({page: {curr: 1}}); //数据刷新
                          } else {
                              layer.msg(res.msg);
                          }
                      },
                      error: function (err) {
                      }
                  });
                  break;
              case 'setting':
                  layer.msg(checkStatus.isAll ? '全选': '未全选');
                  break;
          };
      });

      var $ = layui.$, active = {
          search: function(){
              var monthField = $('#layui-form-month');
              var userNameField = $('#layui-form-user-name');

              //执行重载
              tableIns.reload({
                  page: {
                      curr: 1 //重新从第 1 页开始
                  }
                  ,where: {
                      month: monthField.val(),
                      userName: userNameField.val()+''
                  }
              });
          }
      };
      $('.layui-form .layui-form-item .layui-btn').on('click', function(){
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
      });


  });
</script>
</body>
</html>